<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 
    实现一个 base-input 组件，让该组件能实现原生 input 的效果。（原生input支持的属性，我base-input 组件都要支持。）
   -->

    <div id="app"></div>

    <script src="../lib/vue-3.js"></script>

    <script>
      const app = Vue.createApp({
        template: `
          <base-input 
            label="用户姓名" 
            type="text" 
            placeholder="username" 
            maxlength="2" readonly 
            @focus="onFocus"
            />

          <base-input label="用户密码" type="password" placeholder="password" maxlength="3" />
        `,

        methods: {
          onFocus() {
            console.log("onFocus");
          },
        },
      });

      app.component("base-input", {
        inheritAttrs: false,
        // props: ["label", "type", "placeholder", "maxlength"],
        props: ["label"],
        template: `
          <div>
            <label>
              <span>{{ label }}: </span>
              <input
                v-bind="$attrs"
                />
            </label>
          </div>
        `,
      });

      app.mount("#app");
    </script>
  </body>
</html>
